package com.itheima.consumer.controller;


import com.itheima.consumer.config.RestTemplateConfig;
import com.itheima.consumer.domain.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * 服务的调用方
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/goods/{id}")
    public Goods findGoodsById(@PathVariable("id") int id){
        System.out.println("findGoodsById.........."+id);
        /**
         *  远程调用goods服务中的findOne接口
         *  使用RestTemplate
         *  1.定义bean restTemplate
         *  2.注入bean
         *  3.调用方法
         */
        //3.调用方法
        String url="http://localhost:8000/goods/findOne/"+id;
        Goods goods = restTemplate.getForObject(url, Goods.class);
        return goods;
    }
}
